using System;
using System.Collections.Generic;
using System.Text;
using Cassini;
using System.Diagnostics;
using System.Configuration;
using System.IO;

namespace CassiniStarter
{
    class Program
    {
        static string url = "http://localhost:89/messege/index.aspx";
        //static string path = @"..\..\..\MyMessenger.Web";

        static void Main(string[] args)
        {
            string webAppFromConfig = ConfigurationManager.AppSettings["webapp"];
            string webAppAbsPath = new DirectoryInfo(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, webAppFromConfig)).FullName;

            Server server = new Server(89, "/", webAppAbsPath);
            server.Start();


            Process pr = new Process();
            pr.StartInfo = new ProcessStartInfo("iexplore", url);
            pr.Start();
    
            string cmd = "ready";
            while ((cmd = Console.ReadLine()) != "")
            {
                if (cmd == "run")
                {
                    pr = new Process();
                    pr.StartInfo = new ProcessStartInfo("iexplore", url);
                    pr.Start();
                }

                if (cmd == "test")
                {
                    RunTests();
                }
            }

            server.Stop();

            try
            {
                pr.Kill();
            }
            catch (Exception) { }

        }

        public static void RunTests()
        {
//            Process pr = new Process();
  //          pr.StartInfo = new ProcessStartInfo(@"C:\program files\NUnit 2.4\bin\clr.bat", "2.0 start nunit.exe");
    //        pr.StartInfo.WorkingDirectory = @"C:\program files\NUnit 2.4\bin\";
      //      pr.Start();

        }
    }
}
